
package com.woniuxy.yogaapp.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;

import com.woniuxy.yogaapp.pojo.Coach;
import com.woniuxy.yogaapp.pojo.Student;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface StudentMapper {

	/**
	 * 查询所有学员
	 * 
	 * @return
	 */
	@Select("select * from student")
	public List<Student> findAllStudent();

	// 查看我的签约教练(根据学生id查询教练)
	@Select("select * from student where sid=#{sid}")
	@Results({ @Result(id = true, column = "sid", property = "sid"), @Result(column = "sname", property = "sname"),
			@Result(column = "sid", property = "coachs", many = @Many(select = "BySidCoach")) })
	public Student findBySidCoach(int sid);

	@Select("select * from coachstudent cs , coach c where cs.cid=c.cid and cs.sid=#{sid}")
	public List<Coach> BySidCoach(int sid);

	// 插入新学员
	@Insert("insert into student(sname,stel,sqq,sage,ssex,simage, "
			+ "spower,snickname,uid,smail) values (#{sname},#{stel},#{sqq},"
			+ "#{sage},#{ssex},#{simage},#{spower} ,#{snickname},#{uid},#{smail})")
	public int addStudentInfo(Student student);

	// 根据用户id 查询该用户是否存在（新用户判断）
	@Select("select *from student where uid=#{uid}")
	public Student findStudentByUid(Student student);

	// 老用户 修改个人信息
	@Update("update student set  sname=#{sname},stel=#{stel},sqq=#{sqq}"
			+ ",sage=#{sage},ssex=#{ssex},simage=#{simage},spower=#{spower}"
			+ ",snickname=#{snickname},smail=#{smail} where uid=#{uid}")
	public int updateStudentInfo(Student student);

	// 根据用户uid 查询该用户
	@Select("select *from student where uid=#{uid}")
	public Student findUid(int uid);
}
